#!/usr/bin/env python
#coding: utf-8
from evdev import InputDevice
from select import select
from speak import gen_audio
import sys
import os

def detectInputKey():
    dev = InputDevice('/dev/input/event4')
    print("\033[34m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
    with open("text.txt") as f:
        temp = 0
        while True:
            select([dev], [], [])
            for event in dev.read():
                if event.code == 57:
                    if temp == 0:
                        text = f.readline()
                        gen_audio(text)
                        print(text.strip())
                        os.system("play -q auido.mp3")
                        temp += 1
                    else:
                        temp = 0
                elif event.code == 16:
                    return

            
if __name__ == '__main__':
    detectInputKey()
